package com.github.fujianlian.klinechart.draw;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;

import com.github.fujianlian.klinechart.BaseKLineChartView;
import com.github.fujianlian.klinechart.R;
import com.github.fujianlian.klinechart.base.IChartDraw;
import com.github.fujianlian.klinechart.base.IValueFormatter;
import com.github.fujianlian.klinechart.entity.ICCI;
import com.github.fujianlian.klinechart.formatter.ValueFormatter;
import com.github.fujianlian.klinechart.utils.ViewUtil;

/**
 * KDJ实现类
 * Created by tifezh on 2016/6/19.
 */

public class CCIDraw implements IChartDraw<ICCI> {
    private Paint mCCIPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private Paint mLine1Paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private Paint mLine2Paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    public CCIDraw(BaseKLineChartView view) {
        mCCIPaint.setColor(ContextCompat.getColor(view.getContext(), R.color.chart_white));
        mCCIPaint.setTextSize(ViewUtil.Dp2Px(view.getContext() ,10));
        mLine1Paint.setColor(ContextCompat.getColor(view.getContext(), R.color.chart_red));
        mLine2Paint.setColor(ContextCompat.getColor(view.getContext(), R.color.chart_green));
    }

    @Override
    public void drawTranslated(@Nullable ICCI lastPoint, @NonNull ICCI curPoint, float lastX, float curX, @NonNull Canvas canvas, @NonNull BaseKLineChartView view, int position) {
        view.drawVolLine(this, canvas, mCCIPaint, lastX, lastPoint.getCCI(), curX, curPoint.getCCI());
        view.drawVolLine(this, canvas, mLine1Paint, lastX,100, curX, 100);
        view.drawVolLine(this, canvas, mLine2Paint, lastX, -100, curX, -100);
    }

    @Override
    public void drawText(@NonNull Canvas canvas, @NonNull BaseKLineChartView view, int position, float x, float y) {
        ICCI point = (ICCI) view.getItem(position);
        String text = "CCI(14)  ";
        canvas.drawText(text, x, y, view.getTextPaint());
        x += view.getTextPaint().measureText(text);
        text = "cci:" + view.formatValue(point.getCCI()) + " ";
        canvas.drawText(text, x, y, mCCIPaint);
    }

    @Override
    public float getMaxValue(ICCI point) {
        return Math.max(point.getCCI(), point.getCCI());
    }

    @Override
    public float getMinValue(ICCI point) {
        return Math.min(point.getCCI(), point.getCCI());
    }

    @Override
    public IValueFormatter getValueFormatter() {
        return new ValueFormatter();
    }

    /**
     * 设置K颜色
     */
    public void setKColor(int color) {
        mCCIPaint.setColor(color);
    }

    /**
     * 设置D颜色
     */
    public void setDColor(int color) {
    }

    /**
     * 设置J颜色
     */
    public void setJColor(int color) {
    }

    /**
     * 设置曲线宽度
     */
    public void setLineWidth(float width) {
        mCCIPaint.setStrokeWidth(width);
 
    }

    /**
     * 设置文字大小
     */
    public void setTextSize(float textSize) {
        mCCIPaint.setTextSize(textSize);
    }
}
